#define DEBUG
#include <cstdio>
#define MAXN 100000
#define MAXK 17
#define MAXM 100000
#define MODS 1000000007

using namespace std;

void init_set(int *set, int n) {
  for (int i=1; i<=n; i++) {
    set[i]=i;
  }
}

int get_fa(int *set, int o) {
  if (set[o]!=o) {
    set[o]=get_fa(set, set[o]);
  }
  return set[o];
}

void merge_st(int st[][MAXN+1], int o, int x, int y) {
  if (o>=0 && get_fa(st[o], x)!=get_fa(st[o], y)) {
    st[o][get_fa(st[o], y)]=get_fa(st[o], x);
    merge_st(st, o-1, x, y);
    merge_st(st, o-1, x+(1<<(o-1)), y+(1<<(o-1)));
  }
}

int main() {
#ifdef DEBUG
  freopen("4633.in", "r", stdin);
  freopen("4633.out", "w", stdout);
#endif
  
  int n, m;
  scanf("%d %d", &n, &m);
  static int st[MAXK+1][MAXN+1];
  for (int i=0; (1<<i)<=n; i++) {
    init_set(st[i], n);
  }
  for (int i=1; i<=m; i++) {
    int l1, r1, l2, r2;
    scanf("%d %d %d %d", &l1, &r1, &l2, &r2);
    for (int i=MAXK; i>=0; i--) {
      if ((1<<i)<=r1-l1+1) {
	merge_st(st, i, l1, l2);
	merge_st(st, i, r1-(1<<i)+1, r2-(1<<i)+1);
      }
    }
  }

  static bool book[MAXN+1];
  book[get_fa(st[0], 1)]=true;
  long long ans=9;
  for (int i=2; i<=n; i++) {
    if (!book[get_fa(st[0], i)]) {
      book[get_fa(st[0], i)]=true;
      ans = ans*10%MODS;
    }
  }
  printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
